package com.jl.jlapp.mvp.activity;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.ClipData;
import android.content.ComponentName;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ResolveInfo;
import android.graphics.Bitmap;
import android.net.Uri;
import android.net.http.SslError;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Parcelable;
import android.util.Log;
import android.webkit.DownloadListener;
import android.webkit.JavascriptInterface;
import android.webkit.JsResult;
import android.webkit.SslErrorHandler;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.jl.jlapp.R;
import com.jl.jlapp.eneity.PresellMsg;
import com.jl.jlapp.nets.CommonObserver;
import com.jl.jlapp.nets.Net;

import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class CustomerServiceActivity
        extends Activity {
    private static final int FILECHOOSER_RESULTCODE = 1;
    @BindView(R.id.customer_service_web)
    WebView customerServiceWeb;
    int goodsId = 0;
    private Uri imageUri;
    int isPresell = 0;
    int isVip = 0;
    private ValueCallback<Uri[]> mUploadCallbackAboveL;
    private ValueCallback<Uri> mUploadMessage;
    @BindView(R.id.root_linear)
    LinearLayout rootLinear;
    int userId = 0;
    String userName = "";
    String userPhone = "";

    @TargetApi(21)
    private void onActivityResultAboveL(int paramInt1, int paramInt2, Intent paramIntent) {
        if ((paramInt1 != 1) || (this.mUploadCallbackAboveL == null)) {
            return;
        }
        Uri[] localObject1 = null;
        if (paramInt2 == -1) {
            if (paramIntent != null) {
                String str = paramIntent.getDataString();
                ClipData localClipData = paramIntent.getClipData();
                if (localClipData != null) {
                    localObject1 = new Uri[localClipData.getItemCount()];
                    paramInt1 = 0;
                    for (; ; ) {
                        if (paramInt1 >= localClipData.getItemCount()) {
                            break;
                        }
                        localObject1[paramInt1] = localClipData.getItemAt(paramInt1).getUri();
                        paramInt1 += 1;
                    }
                }
                if (str != null) {
                    localObject1 = new Uri[1];
                    localObject1[0] = Uri.parse(str);
                }
            } else {
                localObject1 = new Uri[1];
                localObject1[0] = this.imageUri;
            }
        }

        this.mUploadCallbackAboveL.onReceiveValue(localObject1);
        this.mUploadCallbackAboveL = null;
    }

    private void takePhoto() {
        Object localObject = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "MyApp");
        if (!((File) localObject).exists()) {
            ((File) localObject).mkdirs();
        }
        this.imageUri = Uri.fromFile(new File(localObject + File.separator + "IMG_" + String.valueOf(System.currentTimeMillis()) + ".jpg"));
        localObject = new ArrayList();
        Intent localIntent1 = new Intent("android.media.action.IMAGE_CAPTURE");
        Iterator localIterator = getPackageManager().queryIntentActivities(localIntent1, 0).iterator();
        while (localIterator.hasNext()) {
            ResolveInfo localResolveInfo = (ResolveInfo) localIterator.next();
            String str = localResolveInfo.activityInfo.packageName;
            Intent localIntent2 = new Intent(localIntent1);
            localIntent2.setComponent(new ComponentName(localResolveInfo.activityInfo.packageName, localResolveInfo.activityInfo.name));
            localIntent2.setPackage(str);
            localIntent2.putExtra("output", this.imageUri);
            ((List) localObject).add(localIntent2);
        }
        localIntent1 = new Intent("android.intent.action.GET_CONTENT");
        localIntent1.addCategory("android.intent.category.OPENABLE");
        localIntent1.setType("image/*");
        localIntent1 = Intent.createChooser(localIntent1, "Image Chooser");
        localIntent1.putExtra("android.intent.extra.INITIAL_INTENTS", (Parcelable[]) ((List) localObject).toArray(new Parcelable[0]));
        startActivityForResult(localIntent1, 1);
    }

    public void getPreSellActivityInformationByGoodsDetailsId(Integer paramInteger) {
        Net.get().getPreSellActivityInformationByGoodsDetailsId(paramInteger.intValue(), 0)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(new CommonObserver<PresellMsg>() {
            @Override
            protected void onError(String errorMsg) {

            }

            @Override
            protected void onSuccess(PresellMsg presellMsg) {

            }
        });
    }

    public void init() {
        WebSettings localWebSettings = this.customerServiceWeb.getSettings();
        localWebSettings.setSaveFormData(false);
        localWebSettings.setLoadWithOverviewMode(true);
        localWebSettings.setJavaScriptEnabled(true);
        localWebSettings.setSupportZoom(true);
        localWebSettings.setUseWideViewPort(true);
        localWebSettings.setDomStorageEnabled(true);
        localWebSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        if (Build.VERSION.SDK_INT >= 21) {
            localWebSettings.setMixedContentMode(0);
        }
        localWebSettings.setLoadWithOverviewMode(true);
        this.customerServiceWeb.setWebViewClient(new WebViewClient() {
            public void onPageFinished(WebView paramAnonymousWebView, String paramAnonymousString) {
                super.onPageFinished(paramAnonymousWebView, paramAnonymousString);
            }

            public void onPageStarted(WebView paramAnonymousWebView, String paramAnonymousString, Bitmap paramAnonymousBitmap) {
                super.onPageStarted(paramAnonymousWebView, paramAnonymousString, paramAnonymousBitmap);
            }

            public void onReceivedSslError(WebView paramAnonymousWebView, SslErrorHandler paramAnonymousSslErrorHandler, SslError paramAnonymousSslError) {
                paramAnonymousSslErrorHandler.proceed();
            }

            public boolean shouldOverrideUrlLoading(WebView paramAnonymousWebView, String paramAnonymousString) {
                return super.shouldOverrideUrlLoading(paramAnonymousWebView, paramAnonymousString);
            }
        });
        this.customerServiceWeb.setWebChromeClient(new WebChromeClient() {
            public boolean onShowFileChooser(WebView paramAnonymousWebView, ValueCallback<Uri[]> paramAnonymousValueCallback, FileChooserParams paramAnonymousFileChooserParams) {
//                CustomerServiceActivity.access$002(CustomerServiceActivity.this, paramAnonymousValueCallback);
                CustomerServiceActivity.this.takePhoto();
                return true;
            }

            public void openFileChooser(ValueCallback<Uri> paramAnonymousValueCallback) {
//                CustomerServiceActivity.access$202(CustomerServiceActivity.this, paramAnonymousValueCallback);
                CustomerServiceActivity.this.takePhoto();
            }

            public void openFileChooser(ValueCallback<Uri> paramAnonymousValueCallback, String paramAnonymousString) {
//                CustomerServiceActivity.access$202(CustomerServiceActivity.this, paramAnonymousValueCallback);
                CustomerServiceActivity.this.takePhoto();
            }

            public void openFileChooser(ValueCallback<Uri> paramAnonymousValueCallback, String paramAnonymousString1, String paramAnonymousString2) {
//                CustomerServiceActivity.access$202(CustomerServiceActivity.this, paramAnonymousValueCallback);
                CustomerServiceActivity.this.takePhoto();
            }
        });
        this.customerServiceWeb.setDownloadListener(new MyWebViewDownLoadListener());
        this.customerServiceWeb.addJavascriptInterface(new DemoJavaScriptInterface(), "demo");
        this.customerServiceWeb.loadUrl("http://117.158.178.202:8004/JLKF/chatClient?loginName=" + this.userPhone + "&userName=" + this.userName + "&isVip=" + this.isVip + "&clientId=" + this.userId + "");
    }

    protected void onActivityResult(int paramInt1, int paramInt2, Intent paramIntent) {
        super.onActivityResult(paramInt1, paramInt2, paramIntent);
        if ((paramInt1 != 1) || ((this.mUploadMessage == null) && (this.mUploadCallbackAboveL == null))) {
        }
        Uri localUri;
        do {
            if ((paramIntent == null) || (paramInt2 != -1)) {
            }
            for (localUri = null; this.mUploadCallbackAboveL != null; localUri = paramIntent.getData()) {
                onActivityResultAboveL(paramInt1, paramInt2, paramIntent);
                return;
            }
        } while (this.mUploadMessage == null);
        Log.e("Mr.Kang", "onActivityResult: " + localUri);
        if (localUri == null) {
            this.mUploadMessage.onReceiveValue(this.imageUri);
            this.mUploadMessage = null;
            Log.e("Mr.Kang", "onActivityResult: " + this.imageUri);
            return;
        }
        this.mUploadMessage.onReceiveValue(localUri);
        this.mUploadMessage = null;
    }

    protected void onCreate(Bundle paramBundle) {
        super.onCreate(paramBundle);
        setContentView(R.layout.activity_customer_service);
        ButterKnife.bind(this);
        SharedPreferences jlAppData = getSharedPreferences("JLAppData", 0);

        this.userPhone = jlAppData.getString("mobile", "");
        this.userName = jlAppData.getString("userName", "");
        this.isVip = jlAppData.getInt("isVip", 0);
        this.userId = jlAppData.getInt("userId", 0);
        Log.d("aaaaaweb", "phone:" + this.userPhone);
        init();
    }

    protected void onDestroy() {
        super.onDestroy();
        Log.d("aaaaaaaaaaaaaaaaaaaa", "我被销毁了");
        this.rootLinear.removeView(this.customerServiceWeb);
        this.customerServiceWeb.destroy();
        this.customerServiceWeb.clearCache(true);
        this.customerServiceWeb.clearHistory();
        this.customerServiceWeb.clearFormData();
    }

    final class DemoJavaScriptInterface {
        DemoJavaScriptInterface() {
        }

        @JavascriptInterface
        public void backFunction() {
            CustomerServiceActivity.this.finish();
        }

        @JavascriptInterface
        public void callDial(String paramString) {
            Intent intent = new Intent("android.intent.action.DIAL", Uri.parse("tel:" + paramString));
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            CustomerServiceActivity.this.startActivity(intent);
        }

        @JavascriptInterface
        public void clickOnAndroid(String paramString1, String paramString2) {
            CustomerServiceActivity.this.goodsId = Integer.parseInt(paramString1);
            CustomerServiceActivity.this.isPresell = Integer.parseInt(paramString2);
            if (CustomerServiceActivity.this.isPresell == 1) {
                CustomerServiceActivity.this.getPreSellActivityInformationByGoodsDetailsId(Integer.valueOf(CustomerServiceActivity.this.goodsId));
                return;
            }
            Intent intent = new Intent(CustomerServiceActivity.this, GoodsDetailActivity.class);
            intent.putExtra("goodsId", CustomerServiceActivity.this.goodsId);
            intent.putExtra("activityId", 0);
            CustomerServiceActivity.this.startActivity(intent);
        }

        @JavascriptInterface
        public void showToast(String paramString) {
            Toast.makeText(CustomerServiceActivity.this, paramString, Toast.LENGTH_LONG).show();
        }
    }

    final class MyWebChromeClient
            extends WebChromeClient {
        MyWebChromeClient() {
        }

        public boolean onJsAlert(WebView paramWebView, String paramString1, String paramString2, JsResult paramJsResult) {
            Log.d("webview", paramString2);
            paramJsResult.confirm();
            return true;
        }
    }

    private class MyWebViewDownLoadListener
            implements DownloadListener {
        private MyWebViewDownLoadListener() {
        }

        public void onDownloadStart(String paramString1, String paramString2, String paramString3, String paramString4, long paramLong) {
            Log.i("tag", "url=" + paramString1);
            Log.i("tag", "userAgent=" + paramString2);
            Log.i("tag", "contentDisposition=" + paramString3);
            Log.i("tag", "mimetype=" + paramString4);
            Log.i("tag", "contentLength=" + paramLong);
            Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(paramString1));
            CustomerServiceActivity.this.startActivity(intent);
        }
    }
}


/* Location:              /Users/davidzhang/Documents/decompileApk/jlfood-dex2jar.jar!/com/jl/jlapp/mvp/activity/CustomerServiceActivity.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */